package com.bus.core.dao.impl;

import org.springframework.stereotype.Repository;

import com.bus.common.hibernate4.Updater;
import com.bus.common.jpa.JpaBaseDao;
import com.bus.core.dao.BusUserSiteDao;
import com.bus.core.entity.BusUserSite;

@Repository
public class BusUserSiteDaoImpl extends JpaBaseDao<BusUserSite, Integer>
		implements BusUserSiteDao {
	public BusUserSite findById(Integer id) {
		BusUserSite entity = get(id);
		return entity;
	}

	public BusUserSite save(BusUserSite bean) {
		getEntityManager().persist(bean);
		return bean;
	}

	public int deleteBySiteId(Integer siteId) {
		String hql = "delete from BusUserSite bean where bean.site.id=:siteId";
		return getEntityManager().createQuery(hql).setParameter("siteId", siteId)
				.executeUpdate();
	}

	public BusUserSite deleteById(Integer id) {
		BusUserSite entity = super.get(id);
		if (entity != null) {
			getEntityManager().remove(entity);
		}
		return entity;
	}

	public void delete(BusUserSite entity) {
		getEntityManager().remove(entity);
	}

	@Override
	protected Class<BusUserSite> getEntityClass() {
		return BusUserSite.class;
	}

	@Override
	public BusUserSite updateByUpdater(Updater<BusUserSite> updater) {
		// TODO Auto-generated method stub
		return null;
	}
}